package net.qiqbframework.messaging;

import net.qiqbframework.common.IdentifierFactory;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class BatchMessage<M extends Message<?>> implements Message<List<M>> {

    private final List<M> messages = new ArrayList<>();

    private final Class<M> messageType;

    public BatchMessage(Class<M> messageType) {
        this.messageType = messageType;
    }

    public void addMessage(M m) {
        this.messages.add(m);
    }

    @Override
    public String getIdentifier() {
        return IdentifierFactory.getInstance().generate();
    }

    @Override
    public MetaData getMetaData() {
        return null;
    }


    @Override
    public List<M> getPayload() {
        return messages;
    }

    @Override
    public Class getPayloadType() {
        return List.class;
    }

    @Override
    public void withMetaData(@Nonnull Map<String, ?> metaData) {

    }

    @Override
    public void andMetaData(@Nonnull Map<String, ?> metaData) {

    }

    /**
     * 消息负载类型
     *
     * @return
     */
    public Class<M> getMessagePayloadType() {
        return null;
    }

    /**
     * 消息类型
     *
     * @return
     */
    public Class<M> getMessageType() {
        return messageType;
    }


}
